package com.example.java.thread;

import java.util.concurrent.*;

public class ThreadApp {

    private static void threadPoolTest(){
        ExecutorService service = Executors.newFixedThreadPool(2);
        Sheets sheets = new Sheets();
        service.submit(new SheetTaskRunner1(sheets));
        service.submit(new SheetTaskRunner2(sheets));
        while (sheets.getSheet(1) < 100 || sheets.getSheet(2) < 100){
            Thread.yield();
        }
        if (!service.isShutdown()){
//            service.shutdown();
        }
        System.out.println(sheets.getSheet(1));
        System.out.println(sheets.getSheet(2));
    }

    private static void testPool(){
        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(100);
        ThreadFactory threadFactory = r -> null;
        RejectedExecutionHandler handler = (r, executor) -> {};
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2,5,2000L,TimeUnit.MILLISECONDS,workQueue,threadFactory,handler);
        threadPoolExecutor.execute(() -> System.out.println("iloveu"));
//        threadPoolExecutor.shutdown();
    }
}
